package mapEditor.view.panels
{
	import asset.mapEditor.panelPutAsset;
	
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	
	import mapEditor.common.DisplayObjectManager;
	import mapEditor.model.EditorModel;

	public class PanelPutView extends PanelItemBaseView
	{
		private var _model:EditorModel;
		public var panelPutAssetView:panelPutAsset;
		private var _previewObject:DisplayObject;
		
		public function PanelPutView(model:EditorModel)
		{
			super();
			_model=model;
			setView();
			setEvent();
		}
		
		private function setView():void
		{
			panelPutAssetView=new panelPutAsset();
			addChild(panelPutAssetView);
		}
		
		private function setEvent():void
		{
			panelPutAssetView.chkIsGrid.addEventListener(MouseEvent.CLICK, __onCheckBoxClick);
			panelPutAssetView.chkIsBottom.addEventListener(MouseEvent.CLICK, __onCheckBoxClick);
			panelPutAssetView.chkIsFloor.addEventListener(MouseEvent.CLICK, __onCheckBoxClick);
			panelPutAssetView.chkIsMirror.addEventListener(MouseEvent.CLICK, __onCheckBoxClick);
		}
		
		private function removeEvent():void
		{
			panelPutAssetView.chkIsGrid.removeEventListener(MouseEvent.CLICK, __onCheckBoxClick);
			panelPutAssetView.chkIsBottom.removeEventListener(MouseEvent.CLICK, __onCheckBoxClick);
			panelPutAssetView.chkIsFloor.removeEventListener(MouseEvent.CLICK, __onCheckBoxClick);
			panelPutAssetView.chkIsMirror.addEventListener(MouseEvent.CLICK, __onCheckBoxClick);
		}
		
		private function __onCheckBoxClick(evt:MouseEvent):void
		{
			switch(evt.currentTarget)
			{
				case panelPutAssetView.chkIsGrid:
					_model.assetIsGrid=panelPutAssetView.chkIsGrid.selected;
					break;
				case panelPutAssetView.chkIsBottom:
					_model.assetIsBottom=panelPutAssetView.chkIsBottom.selected;
					break;
				case panelPutAssetView.chkIsFloor:
					_model.assetIsFloor=panelPutAssetView.chkIsFloor.selected;
					break;
				case panelPutAssetView.chkIsMirror:
					_model.assetIsMirror=panelPutAssetView.chkIsMirror.selected;
					break;
			}
			
		}
		
		/**
		 *预览显示对象 
		 */		
		public function get previewObject():DisplayObject
		{
			return _previewObject;
		}
		
		/**
		 *预览显示对象 
		 */
		public function set previewObject(value:DisplayObject):void
		{
			if(_previewObject && _previewObject.parent) _previewObject.parent.removeChild(_previewObject);
			_previewObject=null;
			
			_previewObject = value;
			if(!_previewObject) return;
			
			panelPutAssetView.boxPreview.txtDefault.visible=false;
			DisplayObjectManager.thumbnailShow(_previewObject, 38, 38);
			panelPutAssetView.boxPreview.addChild(_previewObject);
		}
		
		override public function dispose():void
		{
			super.dispose();
			removeEvent();
			_model=null;
			
			if(_previewObject && _previewObject.parent) _previewObject.parent.removeChild(_previewObject);
			_previewObject=null;
			
			if(panelPutAssetView.parent) panelPutAssetView.parent.removeChild(panelPutAssetView);
			panelPutAssetView=null;
			
			if(parent) parent.removeChild(this);
		}
	}
}